#!/bin/bash
# 快速检查 CMDB 服务

echo "=========================================="
echo "   CMDB 服务快速检查"
echo "=========================================="
echo ""

# 检查后端
echo "🔧 后端服务 (端口 8000):"
if curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/admin/ | grep -q "200\|301\|302"; then
    echo "  ✅ 后端正常运行"
    echo "  访问: http://localhost:8000/admin/"
else
    echo "  ❌ 后端未响应"
fi
echo ""

# 检查前端
echo "🎨 前端服务 (端口 8080):"
if curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 | grep -q "200"; then
    echo "  ✅ 前端正常运行"
    echo "  访问: http://localhost:8080"
else
    echo "  ❌ 前端未响应"
fi
echo ""

# 检查进程
echo "📊 进程状态:"
BACKEND_COUNT=$(ps aux | grep -v grep | grep -c "daphne.*backend.asgi")
FRONTEND_COUNT=$(ps aux | grep -v grep | grep -c "vite")
echo "  后端进程: $BACKEND_COUNT 个"
echo "  前端进程: $FRONTEND_COUNT 个"
echo ""

# 检查端口
echo "🔌 端口监听:"
if command -v ss &> /dev/null; then
    ss -tulnp 2>/dev/null | grep -E ":(8000|8080) " | awk '{print "  " $5}' || echo "  无法获取端口信息"
elif command -v netstat &> /dev/null; then
    netstat -tulnp 2>/dev/null | grep -E ":(8000|8080) " | awk '{print "  " $4}' || echo "  无法获取端口信息"
fi
echo ""

echo "=========================================="
echo "快速测试："
echo "  curl http://localhost:8000/api/"
echo "  curl http://localhost:8080"
echo "=========================================="
